/**
Company: Sarkar software technologys
WebSite: http://www.sarkar.cn
Author: yeganaaa
Date : 5/19/18
Time: 5:02 PM
 */

package Cn.Sarkar.MMS.WebAPI

import Cn.Sarkar.EntityDream.CoreEngine.RDBMS.Core.QueryBuilderExtensions.SelectQueryExpression.contains
import Cn.Sarkar.EntityDream.CoreEngine.RDBMS.Core.QueryBuilderExtensions.SelectQueryExpression.where
import Cn.Sarkar.MMS.DataBaseDefinations.Additional.Names
import Cn.Sarkar.MMS.Entities.DataSources.IDataSource
import io.ktor.locations.Location
import io.ktor.locations.get
import io.ktor.locations.location
import io.ktor.response.respond
import io.ktor.routing.Route


fun Route.useNameController() {

    @Location("Name")
    class Name

    @Location("Search")
    data class Search(val KeyWord: String)

    location<Name> {
        get<Search> {

            val data = IDataSource.openAndAutoClose { db ->
                db.names.where { Names.Ug contains it.KeyWord }.toTypedArray().map {
                    object {
                        val Ug = it.ug
                        val Zh = it.zh
                    }
                }
            }

            context.respond(data)
        }
    }
}



